package com.tms.app.tms.ui;

import android.content.Intent;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.tms.app.tms.adapter.WayBillAdapter;
import com.tms.app.tms.app.Constant;
import com.tms.app.tms.bean.TestBean;
import com.tms.app.tms.bean.response.WaybillListRes;
import com.tms.app.tms.ui.base.presenter.AbsBaseListP;
import com.tms.app.tms.ui.base.view.IListView;

import org.xutils.http.RequestParams;

/**
 * Created by Administrator on 2017/10/28 0028.
 */

public class WayBillPAbs extends AbsBaseListP {

    private int planIdShowType;
    private int planId;

    public void setPlanIdShowType(int planIdShowType) {
        this.planIdShowType = planIdShowType;
    }

    @Override
    public void setiView(IListView iViewTrade) {
        super.setiView(iViewTrade);
    }

    @Override
    public void onSuccess(String result) {
        super.onSuccess(result);
        WaybillListRes res=gson.fromJson(result,WaybillListRes.class);
        bindDataToView(res);
    }

    private void bindDataToView(WaybillListRes res){
        if (iView==null)
            return;
        if (res.getCode()!=200)
            return;
        WayBillAdapter depthAdapter= iView.getAdapter(0);
        depthAdapter.getData().clear();
        depthAdapter.getData().addAll(res.getData());
        depthAdapter.notifyDataSetChanged();
        iView.refreshComplite("");
    }



    public void getData(String token ,int planId){
        this.token=token;
        this.planId=planId;
        requestType=1;
        RequestParams params=new RequestParams(Constant.WayBillList);
        params.addBodyParameter("token",token);
        params.addBodyParameter("planId",planId+"");

        getObjectFromServer(params);
    }


    @Override
    public void onRefresh() {
        super.onRefresh();
        getData(token,planId);

    }


    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
        if (true){
            WaybillListRes.DataBean dataBean= (WaybillListRes.DataBean) adapter.getData().get(position);
            Intent intent=new Intent(view.getContext(), FeeInfoAC.class);
            intent.putExtra("waybillExecId",dataBean.getWaybillExecId());
            intent.putExtra("showType",1);//0 费用详情 不可操作  1 异常费用详情
            intent.putExtra("waybillNo",dataBean.getWaybillNo());
            intent.putExtra("planIdShowType",planIdShowType);
            iView.startActivity(intent);
        }
    }

}
